package com.shanliao.respone;

import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse<T> implements Serializable {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected String code;

    protected String msg;

    protected T data;

    public static <T> BaseResponse<T> success(T data) {
        return success(data, "成功");
    }

    public static <T> BaseResponse<T> success(T data, String showMsg) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setCode("1");
        response.setMsg(showMsg);
        response.setData(data);

        return response;
    }

    public static <T> BaseResponse<T> fail(String showMsg) {
        return fail("0", showMsg);
    }

    public static <T> BaseResponse<T> fail(String code, String showMsg) {
        BaseResponse<T> response = new BaseResponse<>();
        response.setCode(code);
        response.setMsg(showMsg);
        response.setData(null);

        return response;
    }
}